﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SmartERP.Web.Models;
using SmartERP.Web.ViewModels;

namespace SmartERP.Web.Controllers
{
    public class HomeController : Controller
    {
        private SchoolContext db = new SchoolContext();

        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to kick-start your ASP.NET MVC application.";

            return View();
        }

        public ActionResult About()
        {
            //ViewBag.Message = "Your quintessential app description page.";
            //var data = from student in db.Students
            //           group student by student.EnrollmentDate
            //           into dateGroup
            //           select new EnrollmentDateGroup()
            //                      {
            //                          EnrollmentDate = dateGroup.Key,
            //                          StudentCount = dateGroup.Count()
            //                      };

            var query =
                "SELECT EnrollmentDate, Count(*) AS StudentCount FROM Person WHERE EnrollmentDate IS NOT NULL GROUP BY EnrollmentDate";
            var data = db.Database.SqlQuery<EnrollmentDateGroup>(query);
            return View(data);
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your quintessential contact page.";

            return View();
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}
